﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Web_Pages_UserControls_ShowListPost : System.Web.UI.UserControl
{
    private AdminBLL adminBLL;
    protected void Page_Load(object sender, EventArgs e)
    {
        this.adminBLL = new AdminBLL();
        ShowInfoPost();

    }

    protected void ShowInfoPost()
    {
        List<Posts> listpost = adminBLL.GetIPosts.GetListPostsOfAllUser();

        gvListPost.DataSource = listpost;
        gvListPost.DataBind();
       

    }
    protected void gvListPost_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvListPost.PageIndex = e.NewPageIndex;
    }

    void delete()
    {
        
    }
    protected void gvListPost_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       // string id = gvListPost.DataKeys[e.RowIndex].Values.ToString();
     //
        //Response.Write(id);
            
       
    }
    protected void gvListPost_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        string id = gvListPost.DataKeys[e.NewSelectedIndex].Value.ToString();
        Response.Write(id);
    }

    protected void gvListPost_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        



    }
    protected void gvListPost_RowCommand1(object sender, GridViewCommandEventArgs e)
    {
        List<Posts> listpost = adminBLL.GetIPosts.GetListPostsOfAllUser();

        try
        {

            if (e.CommandName == "Xoa")
            {
                int Id = int.Parse(e.CommandArgument.ToString());

                Response.Write(Id);
                Posts post = adminBLL.GetIPosts.GetPostByIdPost(Id);
                bool kq = adminBLL.GetIPosts.DeletePost(post);


                ShowInfoPost();


            }
        }
        catch
        {
            Response.Write("<script>alert('Chủ đề này đã  có Commnent rồi')</script>");
        }

    }
    
}